//
//  LXCareTableViewCell.m
//  喜马拉雅改良版框架
//
//  Created by liuxin on 15/12/30.
//  Copyright © 2015年 蓝鸥科技. All rights reserved.
//

#import "LXCareTableViewCell.h"

@implementation LXCareTableViewCell
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubViews];
    }
    return  self;
}
-(void)createSubViews{
    UIView *upView = [[UIView alloc]init];
    upView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:upView];
    [upView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(5);
        make.left.right.offset(0);
        make.height.offset(90);
    }];
    
    UITapGestureRecognizer *uptap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(upTapAction)];
    [upView addGestureRecognizer:uptap];
    
    self.albumImage = [[UIImageView alloc]init];
    self.albumImage.backgroundColor = [UIColor redColor];
    [upView addSubview:self.albumImage];
    [self.albumImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.mas_equalTo(10);
        make.bottom.mas_equalTo(-10);
        make.width.mas_equalTo(70);
    }];

    self.titleLabel = [[UILabel alloc]init];
    self.titleLabel.font = [UIFont systemFontOfSize:16];
    [upView addSubview:self.titleLabel];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.albumImage.mas_right).offset(10);
        make.right.offset(-10);
        make.top.mas_equalTo(10);
        make.height.mas_equalTo(25);
    }];
    
    self.trackTitleLabel = [[UILabel alloc]init];
    self.trackTitleLabel.numberOfLines = 0;
    self.trackTitleLabel.font = [UIFont systemFontOfSize:13];
    self.trackTitleLabel.textColor = [UIColor lightGrayColor];
    [upView addSubview:self.trackTitleLabel];
    [self.trackTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel.mas_bottom).offset(5);
        make.bottom.mas_equalTo(-10);
        make.right.equalTo(upView.mas_right).offset(-10);
        make.left.mas_equalTo(self.albumImage.mas_right).offset(10);
    }];
    
    UIView *downView = [[UIView alloc]init];
    downView.backgroundColor = [UIColor colorWithRed:0.927 green:1.000 blue:0.985 alpha:1];
    [self.contentView addSubview:downView];
    [downView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.top.equalTo(upView.mas_bottom);
        make.height.mas_equalTo(50);
    }];
    
    UITapGestureRecognizer *downTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(downTapAction)];
    [downView addGestureRecognizer:downTap];
    
    self.userImage = [[UIImageView alloc]init];
    self.userImage.layer.cornerRadius = 20;
    self.userImage.layer.masksToBounds = YES;
    [downView addSubview:self.userImage];
    [self.userImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(10);
        make.top.mas_equalTo(5);
        make.bottom.mas_equalTo(-5);
        make.width.mas_equalTo(40);
    }];
    
    self.userName = [[UILabel alloc]init];
    self.userName.font = [UIFont systemFontOfSize:13];
    [downView addSubview:self.userName];
    [self.userName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(7);
        make.left.equalTo(self.userImage.mas_right).offset(15);
        make.right.offset(-10);
        make.height.mas_equalTo(15);
    }];
    
    self.personalSignatureLabel = [[UILabel alloc]init];
    self.personalSignatureLabel.font = [UIFont systemFontOfSize:13];
    self.personalSignatureLabel.textColor = [UIColor lightGrayColor];
    [downView addSubview:self.personalSignatureLabel];
    [self.personalSignatureLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.userName.mas_bottom).offset(7);
        make.left.equalTo(self.userImage.mas_right).offset(15);
        make.right.offset(-10);
        make.height.mas_equalTo(15);
    }];
}
-(void)setCellModel:(LXCareModel *)cellModel{
    [self.albumImage sd_setImageWithURL:[NSURL URLWithString:cellModel.albumCover] placeholderImage:[UIImage imageNamed:ImagePlaceHolder]];
    [self.userImage sd_setImageWithURL:[NSURL URLWithString:cellModel.avatar] placeholderImage:[UIImage imageNamed:ImagePlaceHolder]];
    if (cellModel.height<18) {
        [self.titleLabel mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(20);
        }];
        [self.trackTitleLabel mas_updateConstraints:^(MASConstraintMaker *make) {
            make.bottom.mas_equalTo(-17);
        }];
    }
    self.titleLabel.text = cellModel.albumTitle;
    self.trackTitleLabel.text = cellModel.trackTitle;
    self.userName.text = cellModel.nickname;
    self.personalSignatureLabel.text = cellModel.personalSignature;
    self.trackID = cellModel.trackId;
    self.Uid = cellModel.uid;
    self.imageUrl = cellModel.albumCover;
    self.Title = cellModel.trackTitle;
}
- (void)awakeFromNib {
}
-(void)upTapAction{
    [self.careModelDelegate bringIDtoViewController:@"play" ID:self.trackID Image:self.imageUrl Title:self.Title];
}
-(void)downTapAction{
    [self.careModelDelegate bringIDtoViewController:@"album" ID:self.Uid Image:nil Title:nil];
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
